
console.log('background.js-->>>>>');
	
chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
        if(request.type=="doPsw"){
			var map = {};
			var mapstr = window.localStorage.lmUrlMap;
			if (mapstr) {
				// map = eval('(' + mapstr + ')');
				map = JSON.parse(mapstr);
			}
			var doPsw = !map[request.theurl];
            sendResponse({"doPsw":doPsw});
        }else if(request.type=="getPsw"){
			var pmapStr = window.localStorage.pmap;
			sendResponse({"pmapStr":pmapStr});
		}else if(request.type=="setPsw"){
			
			var pmapStr = window.localStorage.pmap;
			var pmap = {};
			if(pmapStr&&pmapStr!=''){
				var dec = decrypts(pmapStr);
				pmap = eval('(' + dec + ')');
				if(!pmap){
					pmap = {};
				}
			}
			var data = request.data;
			pmap[request.theurl] = {
				username:data.username,
				password:data.password
			};
			// window.localStorage.pmap = encrypts(JSON.stringify(pmap));
			//alert(JSON.stringify(pmap));
			pmapStr = encrypts(JSON.stringify(pmap));
			window.localStorage.pmap = pmapStr;
			return;
			
		}
	});

	
chrome.tabs.onActivated.addListener(function(activeInfo) {
	//console.log('background.js-->>>>>onActivated:'+activeInfo);
	//alert('background.js-->>>>>onActivated:'+activeInfo.tabId+","+activeInfo.windowId);
	var map = {};
	var mapstr = window.localStorage.lmUrlMap;
	if (mapstr) {
		// map = eval('(' + mapstr + ')');
		map = JSON.parse(mapstr);
	}
	chrome.tabs.query({
		active: true,
		currentWindow: true
	}, tabs => {
		var thisUrl = getRootUrl(tabs[0].url);
		//alert(map[thisUrl]);
	if(!map[thisUrl]){
		// 恢复正常图标
		chrome.browserAction.setIcon({
			path
		});
	}else{
		//设置灰色图标
		grey_img(path,function(imgObj){
					// 设置灰色图标
					chrome.browserAction.setIcon({
						imageData: imgObj.ctx.getImageData(0,0,128,128)
					});
				});
	}
	});
	
});	
	
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
	//console.log('background.js-->>>>>onActivated:'+activeInfo);
	//alert('background.js-->>>>>onActivated:'+activeInfo.tabId+","+activeInfo.windowId);
	var thisUrl = changeInfo.url;
	//alert(changeInfo.url+"<br>"+thisUrl);
	//alert(thisUrl);
	if(!thisUrl){
		return;
	}
	
	var map = {};
	var mapstr = window.localStorage.lmUrlMap;
	if (mapstr) {
		// map = eval('(' + mapstr + ')');
		map = JSON.parse(mapstr);
	}
	
	thisUrl = getRootUrl(thisUrl);
	if(!map[thisUrl]){
		// 恢复正常图标
		chrome.browserAction.setIcon({
			path
		});
	}else{
		//设置灰色图标
		grey_img(path,function(imgObj){
					// 设置灰色图标
					chrome.browserAction.setIcon({
						imageData: imgObj.ctx.getImageData(0,0,128,128)
					});
				});
	}
	
	
});	


